package com.cdtu.labpreview.controller;

import com.cdtu.labpreview.common.Result;
import com.cdtu.labpreview.common.UserHolder;
import com.cdtu.labpreview.controller.vo.InstrumentVo;
import com.cdtu.labpreview.dto.UserDTO;
import com.cdtu.labpreview.entity.InstrumentIntroduction;
import com.cdtu.labpreview.service.IInstrumentIntroductionService;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 实验仪器介绍模块
 */
@RestController
@RequestMapping("/instrument")
@Api(tags = "实验仪器介绍模块")
public class InstrumentIntroductionController {

    @Autowired
    private IInstrumentIntroductionService instrumentIntroductionService;

    /**
     * 查看实验仪器介绍（老师、学生）
     * @return
     */
    @GetMapping
    public Result getInstrumentPicture(){
        UserDTO userDTO = UserHolder.getUser();
        int no = userDTO.getUserNo();
        int type = userDTO.getType();
        return instrumentIntroductionService.getInstrumentIntroduction(no,type);
    }

    /**
     * 添加实验仪器介绍（老师）
     * @param instrumentVo
     * @return
     */
    @PostMapping
    public Result addInstrumentPicture(@RequestBody InstrumentVo instrumentVo){
        InstrumentIntroduction instrumentIntroduction=new InstrumentIntroduction();
        BeanUtils.copyProperties(instrumentVo,instrumentIntroduction);
        return instrumentIntroductionService.addInstrumentIntroduction(instrumentIntroduction);
    }

    /**
     * 修改实验仪器介绍（老师）
     * @param instrumentIntroduction
     * @return
     */
    @PutMapping
    public Result updateInstrumentPicture(@RequestBody InstrumentIntroduction instrumentIntroduction){
        return instrumentIntroductionService.updateInstrumentIntroduction(instrumentIntroduction);
    }

    /**
     * 删除实验仪器介绍（老师）
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteInstrumentPicture(@PathVariable("id") long id){
        return instrumentIntroductionService.deleteInstrumentIntroduction(id);
    }

}
